package mozi.com.oneday.Fragment;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import mozi.com.oneday.R;

/**
 * Created by 执子一白 on 2017/9/22.
 */

public class WelcomeFragment extends Fragment {
    @Bind(R.id.button)
    Button button;
    @Bind(R.id.button2)
    Button button2;


    LoginFragment loginFragment;
    RegisterFragment registerFragment;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_welcome, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.button, R.id.button2})
    public void onViewClicked(View view) {
        FragmentManager fm = getFragmentManager();
        // 开启Fragment事务
        FragmentTransaction transaction = fm.beginTransaction();
        switch (view.getId()) {
            case R.id.button:
                if (loginFragment == null)
                {
                    loginFragment = new LoginFragment();
                }
                // 使用当前Fragment的布局替代id_content的控件
                transaction.replace(R.id.id_content, loginFragment);
                break;
            case R.id.button2:
                if (registerFragment == null)
                {
                    registerFragment = new RegisterFragment();
                }
                // 使用当前Fragment的布局替代id_content的控件
                transaction.replace(R.id.id_content, registerFragment);
                break;
        }
        transaction.commit();
    }
}
